package thread;

public class ThreadLocal {



        private static java.lang.ThreadLocal<String> tl = new java.lang.ThreadLocal<>();

        private String content;

        private String getContent() {
            return tl.get();
        }

        private void setContent(String content) {
            tl.set(content);
        }

        public static void main(String[] args) {
            ThreadLocal demo = new ThreadLocal();
            for (int i = 0; i < 5; i++) {
                Thread thread = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        demo.setContent(Thread.currentThread().getName() + "的数据");
                        System.out.println("-----------------------");
                        System.out.println(Thread.currentThread().getName() + "--->" + demo.getContent());
                    }
                });
                thread.setName("线程" + i);
                thread.start();
            }
        }

}
